package com.metaera.app.controller.presenter;

import com.metaera.app.controller.core.RequestPresenter;
import com.metaera.app.controller.view.core.INetworkRequestView;
import com.metaera.app.data.DataRepository;
import com.metaera.app.data.rx.ResponseObserver;
import com.metaera.app.data.rx.SchedulersTransformer;

public class LoginVerPresenter extends RequestPresenter<INetworkRequestView<Object>> {

    public void sendSms(String phone_code, String mobile) {

        DataRepository.getInstance()
                .sendSms(
                        phone_code.replace("+", ""),
                        mobile.replace(" ", "")
                )
                .compose(SchedulersTransformer.transformer())
                .subscribe(new ResponseObserver<>(
                                this,
                                mView,
                                response -> mView.successful(response.getData())
                        )
                );
    }


    public void resetPassword(
            String code,
            String mobile,
            String phone_code,
            String password1,
            String password2
    ){
        DataRepository.getInstance()
                .setPassword(
                        code,
                        mobile.replace(" ", ""),
                        phone_code.replace("+", ""),
                        password1,
                        password2
                )
                .compose(SchedulersTransformer.transformer())
                .subscribe(new ResponseObserver<>(
                                this,
                                mView,
                                response -> mView.successful(response.getData())
                        )
                );
    }

    public void forgotPassword(
            String code,
            String mobile,
            String phone_code,
            String password1,
            String password2
    ){
        DataRepository.getInstance()
                .forgotPassword(
                        code,
                        mobile.replace(" ", ""),
                        phone_code.replace("+", ""),
                        password1,
                        password2
                )
                .compose(SchedulersTransformer.transformer())
                .subscribe(new ResponseObserver<>(
                                this,
                                mView,
                                response -> mView.successful(response.getData())
                        )
                );
    }
}
